type typeUser = {
  id: number
  name: string
}
const users: typeUser[] = [
  { id: 101, name: 'Henry' },
  { id: 102, name: 'Tom' }
]

// 箭头函数写法
const queryUser = (
  id: number | string | typeUser
): typeUser | boolean | string => {
  if (typeof id === 'number') {
    return users.filter(user => user.id === id)[0] || 'User not found'
  } else if (typeof id === 'string') {
    return users.filter(user => user.name === id)[0] || 'User not found'
  } else if (typeof id === 'object') {
    return users.push(id as typeUser) ? true : false
  } else {
    return 'Invalid query type'
  }
}

console.log(queryUser(101))
console.log(queryUser(110))
console.log(queryUser('Tom'))
console.log(queryUser({ id: 202, name: 'Elisy' }))
// console.log(queryUser(null)) // 错误，编译不通过，类型“null”的参数不能赋给类型“string | number | typeUser”的参数
// console.log(queryUser(true)) // 错误，编译不通过，类型“boolean”的参数不能赋给类型“string | number | typeUser”的参数

console.log(users)

export {}
